package com.szxy.bean;

import org.junit.jupiter.api.Test;

import java.util.Optional;

/**
 * @Author:zwer
 * @Date:2020/4/17 15:43
 * @Description:com.szxy.bean
 * @Version:1.0
 **/
public class EmployeeServiceTest {

    @Test
    public void test1() {
        EmployeeService empService = new EmployeeService();
        Employee emp = empService.getEmpByEmpId(2);
        System.out.println(emp.getId());
    }

    @Test
    public void test2() {
        EmployeeService empService = new EmployeeService();
        Optional<Employee> empOptional = empService.getEmpOptionalByEmpId(2);
        Employee emp = empOptional.orElse(new Employee());
        System.out.println(emp.getId());
    }

    /**
     * 足条件员工工资 < 4000 元, 都上涨 2000 元
     */
    @Test
    public void test3() {
        EmployeeService empService = new EmployeeService();
        Optional<Employee> op = empService.getEmpOptionalByEmpId(7);
         op = op.filter(emp -> emp.getSalary() < 4000);
        if (op.isPresent()) {
            Optional<Employee> employee = op.map(emp -> {
                emp.setSalary(emp.getSalary() + 2000);
                return emp;
            });
            System.out.println(employee);
        }

    }
}
